<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>文章修改</title>
<link rel="shortcut icon" href="favicon.ico">
<link href="/hmp/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
<link href="/hmp/css/font-awesome.css?v=4.4.0" rel="stylesheet">
<link href="/hmp/css/animate.css" rel="stylesheet">
<link href="/hmp/css/style.css?v=4.1.0" rel="stylesheet">
<link href="/hmp/layui/layui/css/layui.css" rel="stylesheet">
<link href="/hmp/editor.md-master/css/editormd.css" rel="stylesheet">

</head>
<body class="gray-bg">
	<!--第一层  数据展示 -->
	<div class="wrapper wrapper-content animated fadeInRight">
		<!-- Panel Other -->
		<div class="ibox float-e-margins">
			<div class="ibox-content">
				<div class="row row-lg">
					<!-- Example Events -->
					<div class="example-wrap">
						<div class="example">
							<form class="layui-form" action="">
								<div class="layui-form-item">
									<label class="layui-form-label">标题</label>
									<div class="layui-input-block">
									
										<input type="text" name="activeId" id="activeId" 
										 class="hidden" value="${active.activeId}">
										<input type="text" name="title" id="title" required lay-verify="required"
											placeholder="请输入标题" autocomplete="off" class="layui-input" value="${active.title}">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">类型</label>
										<div class="layui-input-block radioType" id="radioType">
									
										</div>
								</div>

				 				 <div class="layui-form-item">
							    <label class="layui-form-label">复选框</label>
							    <div class="layui-input-block tags" id="tags">
							       
							    </div>
							  </div>
							  
								  <!-- MarkDown的id标志 -->
								<div id="my-editormd">
									    <textarea style="display:none;" id="my-editormd-markdown-doc"  name="my-editormd-markdown-doc">${active.text!''}</textarea>
							 	</div>
								</div>
								<div class="layui-form-item">
									<div class="layui-input-block">
										<button class="layui-btn" lay-submit lay-filter="updateActiveForm">立即提交</button>
										<button type="reset" class="layui-btn layui-btn-primary">重置</button>
									</div>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<!-- 底层  占个坑  -->
	<div></div>

</body>

<!-- 全局js -->
<script src="/hmp/js/jquery.min.js"></script>
<script src="/hmp/js/bootstrap.min.js?v=3.3.6"></script>
<!-- 自定义js -->
<script src="/hmp/js/content.js?v=1.0.0"></script>
<script src="/hmp/layui/layui/layui.js"></script>
<script src="/hmp/editor.md-master/editormd.min.js"></script>
 <script type="text/javascript">
	
	var type="${active.type}";
	var tag="${active.tag!''}";
	var strs= new Array(); //定义一数组 
	strs=tag.split(","); //字符分割 
 	
	$(function(){
		
		$("#radioType").html();
		$("#tags").html();
		  //得到所有的类型 
	 	// ***********layui 里里面的复选框 等  要先初始化   才能用  不然有时候会显示不了 ****************   
		layui.use(['form','layer'], function(){
	     var layer = layui.layer;
	  	var form = layui.form;
	    //监听提交
		  form.on('submit(updateActiveForm)', function(data){
		   // layer.msg(JSON.stringify(data.field));
		    $.post("/active/update",data.field,function(result){
		    	 
		    		if(result.code==200)
		    		{
		    			layer.confirm('修改成功', function(index) {
							layer.close(index);
							layer.alert(result.msg);
							//window.parent.location.reload(); //刷新父页面
							//console.log(window.parent.loadTable());
							parent.table.reload('testReload');
			    			var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
			    			parent.layer.close(index); //再执行关闭      
						});
		    			  
		    		}else
		    		{
		    			layer.alert(result.msg);
		    		}
		    });
		    return false;
		  });
		
	
	});
		  
		  
	    $.ajax({
	    	type : "POST",
	    	url : "/activeType/selectAll",
	    	//data :"",
	    	 async: false,  //加了这个属性，
	    	error : function(request) {
				laryer.alert("网络错误!");
			}, 
			success : function(data) {
				
				if (data.code ==200) {
					//拼接 html   
					var tag=data.data;
					var html='';
				 
					for(var i=0;i<tag.length;i++)
					{
					 
						if(tag[i].activeTypeId==type)
						{
							html+='<input type="radio" name="type" value="'+tag[i].activeTypeId+'" title="'+tag[i].typeName+'"  checked="checked">';
						}else{
							
							html+='<input type="radio" name="type" value="'+tag[i].activeTypeId+'" title="'+tag[i].typeName+'"  >';
						
						}
					}
				 
					$("#radioType").html(html);
					
				} else {
					laryer.alert("标签查询失败,请联系管理员")
				}
			}

	    });
		
	    
	    
	    //得到所有的标签
	    $.ajax({
	    	type : "POST",
	    	url : "/activeTag/selectAll",
	    	data :"",
	    	 async: true,  //加了这个属性，
	    	error : function(request) {
				laryer.alert("网络错误!");
			},
			success : function(data) {
				if (data.code ==200) {
					//拼接 html 
					var tag=data.data;
					var html='';
					var bj="No";//一个标示 
					for(var i=0;i<tag.length;i++)
					{
						for(var j=0;j<strs.length;j++)
						{
							if(strs[j]==tag[i].tagName)
							{
								html+='<input type="checkbox" name="tag['+tag[i].tagName+']" value="'+tag[i].tagName+'" title="'+tag[i].tagName+'" checked="checked">';
								bj="Yes";
								break;
							} 
							bj="No";
						}
						if(bj=="No"){
						 html+='<input type="checkbox" name="tag['+tag[i].tagName+']" value="'+tag[i].tagName+'" title="'+tag[i].tagName+'" >';
						}
					}
					//console.log(html);
				 
					$("#tags").html(html);
					
				} else {
					laryer.alert("标签查询失败,请联系管理员")
				}
			}

	    });
	  
		
		
	}) 

</script>
 
<script>
	 
	

	$(function() {
		var showEditor;
		showEditor=editormd("my-editormd", { //注意1：这里的就是上面的DIV的id属性值
	        width: "95%",
	        height: 640,
	        syncScrolling: "single",
	        path: "/hmp/editor.md-master/lib/", //注意2：你的路径
	        syncScrolling: "single",
	        imageUpload: true,
	        imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
	        imageUploadURL: "/file",
	        saveHTMLToTextarea: true, //注意3：这个配置，方便post提交表单
	        //下面这一行将使用dark主题
	       // previewTheme : "dark"
	    });
	});
	
	 
</script>
 





</html>
